//
//  WHMsgSendFailCell.m
//  SquirrelSeller
//
//  Created by 邓伟浩 on 2019/1/7.
//  Copyright © 2019 邓伟浩. All rights reserved.
//

#import "WHMsgSendFailCell.h"
#import "WHNormalDesCell.h"

@interface WHMsgSendFailCell ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *dataTableView;
@property (nonatomic, strong) NSArray *tipsArray;
@property (nonatomic, strong) NSArray *desArray;

@property (nonatomic, strong) UIButton *sendBtn;

@end

@implementation WHMsgSendFailCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initParams];
        [self setUpMsgSendFailUI];
    }
    return self;
}

- (void)initParams {
    _tipsArray = @[@"快递类型", @"运单号", @"取件码", @"收件人电话"];
}

- (void)setUpMsgSendFailUI {
    
    [self.contentView addSubview:({
        _sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _sendBtn.backgroundColor = CMDarkOrangeColor;
        ViewRadius(_sendBtn, kRealwidth(30)/2);
        NSAttributedString *attStr = [[NSAttributedString alloc] initWithString:@"发送" attributes:@{NSFontAttributeName:SYSTEMFONT(kRealwidth(15)), NSForegroundColorAttributeName:KWhiteColor}];
        [_sendBtn setAttributedTitle:attStr forState:UIControlStateNormal];
        _sendBtn;
    })];
    [_sendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(kRealwidth(90));
        make.height.mas_equalTo(kRealwidth(30));
        make.right.mas_equalTo(self.contentView.mas_right).offset(-kRealwidth(15));
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
    }];
    
    [self.contentView addSubview:({
        _dataTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _dataTableView.delegate = self;
        _dataTableView.dataSource = self;
        [_dataTableView registerClass:[WHNormalDesCell class] forCellReuseIdentifier:NSStringFromClass([WHNormalDesCell class])];
        _dataTableView.tableFooterView = [UIView new];
        _dataTableView.backgroundColor = KWhiteColor;
        _dataTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _dataTableView.scrollEnabled = NO;
        _dataTableView;
    })];
    
    [_dataTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.mas_equalTo(self.contentView);
        make.right.mas_equalTo(_sendBtn.mas_left);
    }];
}

#pragma mark - —————— UITableViewDelegate & UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WHNormalDesCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([WHNormalDesCell class]) forIndexPath:indexPath];
    cell.tipsLabel.text = _tipsArray[indexPath.row];
    cell.desLabel.text = _desArray[indexPath.row];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return kRealwidth(35);
}

- (void)setSendModel:(WHMsgSendModel *)sendModel {
    _sendModel = sendModel;
    
    _desArray = @[sendModel.expressCompany, sendModel.waybillNum, sendModel.takeCode, sendModel.recipientsCell];
    [_dataTableView reloadData];
}

@end
